<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>swoole 测试</h1>
<script>
    var url = 'ws://192.168.0.105:9501';
    var websocket = new WebSocket(url);
    //实例化对象的onopen事件
    websocket.onopen = function (evt) {
        websocket.send("我是js里ws.send的内容");
        console.log("我是js的onopen事件");
    }
    //实例化对象的onmessage事件
    websocket.onmessage = function (evt) {
        console.log("我是js里onmessage事件:" + evt.data);
    }
    //实例化对象的onclose事件
    websocket.onclose = function (evt) {
        console.log("我是js里的onclose");
    }
    //实例化对象的onerror事件
    websocket.onerror = function (evt, e) {
        console.log("我是js的error:" + evt.data);
    }
</script>
</body>
</html>